window.addEventListener('load',function(){




let arr=[
      {name:'刘世伟',mima:'123456'}, {name:'root',mima:'123456'},{name:'root1',mima:'123456'}
]
let  ZH=document.getElementById('zhanghao');
let SM=document.getElementById('saoma');
let  bd=document.getElementById('biaodan');
let  em=document.getElementById('erweima');
let an=document.getElementById('anniu')
let name=document.getElementById('name');
let password=document.getElementById('password');
let btn=document.querySelectorAll('form button')
    
ZH.addEventListener('click',function(){
    bd.style.display='block';
      an.style.display='block';
    em.style.display='none';
})


SM.addEventListener('click',function(){
    em.style.display='block';
    an.style.display='none';
    bd.style.display='none';
})





// 密码+账号验证+跳转
an.addEventListener('click',function(){
let name1=document.getElementById('name').value;
let psd=document.getElementById('password').value;
let y=0
  arr.forEach(function(x){
if(name1==x.name && psd==x.mima){
  y=1
  return y
  }
  })

if(y==1){
   alert("登录成功");
  window.location = "index.html";
}
else {
  alert('密码或账号错误')
}
  })





     
btn.forEach(function(v){
     v.addEventListener('click',function(){
       v.style.display='';
       v.previousElementSibling.value='';
     })
})
// 显示
// name.addEventListener('input',function(){
//   let len=this.value.length;
//   if(len>0){
//     btn1.style.display='block';
//   }
//   else{
//     btn1.style.display='';
//   }
// })
// password.addEventListener('input',function(){
//   let len=this.value.length;
//   if(len>0){
//     btn2.style.display='block';
//   }
//   else{
//     btn2.style.display='';
//   }
// })

// 函数封装
function   xianshi(x){
      x.addEventListener('input',function(){
       


        if(this.value.length>0){
          this.nextElementSibling.style.display='block';
          console.log(this.nextElementSibling);
        }
        else{
          this.nextElementSibling.style.display='';
          console.log(this.nextElementSibling);
        }
      })



}
xianshi(name);
xianshi(password);



// // 删除
// btn1.addEventListener('click',function(){
//   name.value='';
// })

// btn2.addEventListener('click',function(){
//   password.value='';
// })

// // 删除




})












